<template>
	<view>
		<view class="orders_type" :style="{top: top+'px'}">
			<text :class="state==0?'active':''" @click="funState(0)">全部</text>
			<text :class="state==1?'active':''" @click="funState(1)">待付款</text>
			<text :class="state==2?'active':''" @click="funState(2)">待发货</text>
			<text :class="state==3?'active':''" @click="funState(3)">待收货</text>
			<text :class="state==4?'active':''" @click="funState(4)">待评价</text>
			<text :class="state==50?'active':''" @click="funState(50)">售后</text>
		</view>
		<view class="orders_list">
			<view class="con" v-for="item in list">
				<view class="state">
					<text>{{item.or_settime}}</text><label>{{item.or_progressName}}</label>
				</view>
				<view class="pro" v-for="pro in item.or_items">
					<image :src="pro.pro_imgs"></image>
					<view class="pron">
						<text>￥{{pro.od_price.toFixed(2)}}</text>
						<label>x{{pro.od_amount}}</label>
					</view>
					<view class="prod">
						<text>{{pro.pro_title}}</text>
						<view class="tags">
							<label v-if="pro.ptag_value1">{{pro.ptag_value1}}</label>
						</view>
					</view>
				</view>
				<view class="totals">
					<text>实付款: ￥{{item.or_price.toFixed(2)}}</text>
				</view>
				<!-- <view class="btns" v-if="item.or_progressState==1">
					<button>去支付</button>
				</view> -->
				<view class="btns" v-if="item.or_progressState==3">
					<button>确认收货</button>
				</view>
				<view class="btns" v-if="item.or_progressState==4">
					<button>去评价</button>
				</view>
			</view>
		</view>
		<!--空信息-->
		<view class="nodata_con" v-if="isLoading==false&&list.length<=0">
			<label class="iconfont icon-meiyoushuju"></label>
			<text>{{$t('no_data')}}</text>
		</view>
		<!--刷新-->
		<view class='loadind_con' v-if="isLoading">
			<view class="loading">
				<view class="loading-bar"></view>
				<view class="loading-bar"></view>
				<view class="loading-bar"></view>
				<view class="loading-bar"></view>
			</view>
		</view>
	</view>
</template>
<script>
	export default {
		data() {
			return {
				top: 0, //状态栏高度
				index: 1, //页数
				size: 10, //条数
				list: [], //列表值
				isLoading: true, //是否正在加载
				state: 0, //状态 0全部 1待付款 2待发货 3待收货 4待评价 50退款/售后
			}
		},
		onReady() {
			uni.setNavigationBarTitle({
				title: this.$t('my_order')
			})
		},
		onLoad(options) {
			var _this = this;
			_this.state = options.state ? options.state : 0;

			//加载列表
			_this.getData();

			//获取状态栏高度
			uni.getSystemInfo({
				success: (result) => {
					console.log(result.statusBarHeight);
					_this.statusBarHeight = result.statusBarHeight;
				},
			});

			//#ifdef H5
			_this.top = 44;
			//#endif

			//定义通讯方法
			uni.$on('load_list_orders', function(data) {
				_this.index = 1;
				_this.list = [];
				_this.isLoading = true;
				_this.getData();
			});
		},
		onUnload() {
			uni.$off("load_list_orders");
		},
		onPullDownRefresh() { //下拉刷新
			var _this = this;
			//清空还原
			_this.index = 1;
			_this.list = [];
			_this.isLoading = true;
			_this.getData();
		},
		onReachBottom() { //上拉到底部刷新
			var _this = this;
			_this.index = _this.index + 1;
			_this.isLoading = true;
			_this.getData();
		},
		methods: {
			//获取内容
			getData: function() {
				var _this = this;
				_this.fun_request("/Api/Orders/GetPageList", {
					index: _this.index,
					size: _this.size,
					count: 0,
					state: _this.state
				}, function(res) {
					var _list = res.data;
					_this.fun_map(_list, function(i, item) {
						item.or_items = JSON.parse(item.or_items);
						//订单状态(0取消订单，1待付款，2付款成功，3已发货，4确认收货，5已评价，6申请退款，7退款成功，8退款失败)
						switch (item.or_progressState) {
							case 0:
								item.or_progressName = "取消订单";
								break;
							case 1:
								item.or_progressName = "待付款";
								break;
							case 2:
								item.or_progressName = "付款成功";
								break;
							case 3:
								item.or_progressName = "已发货";
								break;
							case 4:
								item.or_progressName = "确认收货";
								break;
							case 5:
								item.or_progressName = "已评价";
								break;
							case 6:
								item.or_progressName = "申请退款";
								break;
							case 7:
								item.or_progressName = "退款成功";
								break;
							case 8:
								item.or_progressName = "退款失败";
								break;
						}
					});
					_this.list = _this.list.concat(_list);
					//加载完成
					_this.isLoading = false;
					//下拉刷新 - 停止
					uni.stopPullDownRefresh();
				});
			},
			//选择状态
			funState: function(state) {
				var _this = this;
				_this.state = state;

				//清空还原
				_this.index = 1;
				_this.list = [];
				_this.isLoading = true;
				_this.getData();
			},
			//跳转
			funHref: function(url) {
				this.fun_navigateTo(url);
			},
		}
	}
</script>
<style lang="scss">
	page {
		background: #F7F7F7;
	}

	.orders_type {
		width: 100%;
		height: 90rpx;
		line-height: 90rpx;
		font-size: 32rpx;
		padding: 0;
		background-color: #fff;
		position: fixed;
		top: 0;
		z-index: 99;

		text {
			float: left;
			width: 16.6666666%;
			text-align: center;
			box-sizing: border-box;
			height: 100%;
			font-size: 29rpx;
		}

		text.active {
			border-bottom: 6rpx solid #F85F69;
			color: #F85F69;
		}
	}

	.orders_list {
		display: block;
		padding: 120rpx 3% 30rpx;

		.con {
			display: block;
			width: 100%;
			background-color: #fff;
			border-radius: 20rpx;
			padding: 20rpx;
			margin-bottom: 20rpx;
		}

		.state {
			display: block;
			width: 100%;
			font-size: 32rpx;
			overflow: hidden;

			label {
				float: right;
				color: #F85F69;
				font-size: 28rpx;
			}
		}

		.pro {
			display: block;
			overflow: hidden;
			margin-top: 20rpx;

			image {
				float: left;
				width: 180rpx;
				height: 180rpx;
				border-radius: 20rpx;
			}
		}

		.pron {
			float: right;
			width: 100rpx;
			text-align: right;
			font-size: 28rpx;

			text {
				display: block;
			}

			label {
				display: block;
				color: #999;
				margin-top: 8rpx;
			}
		}

		.prod {
			display: block;
			padding: 0 100rpx 0 200rpx;

			text {
				display: inline-block;
				font-size: 28rpx;
				height: 80rpx;
				overflow: hidden;
			}

			.tags {
				overflow: hidden;
				margin-top: 10rpx;

				label {
					float: left;
					padding: 5rpx 10rpx;
					border: 1px solid #eee;
					font-size: 26rpx;
					color: #999;
					border-radius: 8rpx;
					margin-right: 10rpx;
				}
			}
		}

		.totals {
			display: block;
			text-align: right;
			font-size: 28rpx;
			margin-top: 20rpx;
		}

		.btns {
			display: block;
			overflow: hidden;
			margin-top: 20rpx;

			button {
				float: right;
				height: 60rpx;
				line-height: 60rpx;
				font-size: 26rpx;
				background-color: #F85F69;
				color: #fff;
			}
		}
	}
</style>
